using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace TestAjaxWithASP
{
	/// <summary>
	/// Summary description for WebForm1.
	/// </summary>
	public partial class WebForm1 : System.Web.UI.Page
	{
		protected System.Data.OleDb.OleDbConnection oleDbCon1;
		protected System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;
		protected System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
		protected System.Data.OleDb.OleDbCommand oleDbInsertCommand1;
		protected System.Data.OleDb.OleDbCommand oleDbUpdateCommand1;
		protected System.Data.OleDb.OleDbCommand oleDbDeleteCommand1;
		protected string Choice;
		protected string vStr;
		protected System.Data.OleDb.OleDbDataAdapter DA;
		protected DataSet DS;

		private void Page_Load(object sender, System.EventArgs e)
		{
			if(!IsPostBack)
			{
				Choice=Request["Choice"];
				if(Choice != null)
				{
					Response.Clear();
					if (Choice=="All Cities")
						DA=new System.Data.OleDb.OleDbDataAdapter
							("Select * from Customers",oleDbCon1);
					else
						DA = new System.Data.OleDb.OleDbDataAdapter
							(string.Format("Select * from Sales where CustID={0}",Request["Choice"]),oleDbCon1);
					DS=new DataSet();
					DA.Fill(DS,"Customers");
					vStr=DS.GetXml();
					Response.Clear();
					Response.ContentType="Text/xml";
					Response.Write(vStr);
					Response.End();
				}
				else
				{
					Response.Clear();
					Response.End();
				}
			}
			else
			{
				Response.Clear();
				Response.End();
			}
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}

		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.oleDbCon1 = new System.Data.OleDb.OleDbConnection();
			this.oleDbDataAdapter1 = new System.Data.OleDb.OleDbDataAdapter();
			this.oleDbDeleteCommand1 = new System.Data.OleDb.OleDbCommand();
			this.oleDbInsertCommand1 = new System.Data.OleDb.OleDbCommand();
			this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand();
			this.oleDbUpdateCommand1 = new System.Data.OleDb.OleDbCommand();
			//
			// oleDbCon1
			//
			this.oleDbCon1.ConnectionString = @"Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=0;Data Source=""D:\Documents and Settings\Mina\My Documents\DBTest.mdb"";Jet OLEDB:Engine Type=5;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet OLEDB:SFP=False;persist security info=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1";
			//
			// oleDbDataAdapter1
			//
			this.oleDbDataAdapter1.DeleteCommand = this.oleDbDeleteCommand1;
			this.oleDbDataAdapter1.InsertCommand = this.oleDbInsertCommand1;
			this.oleDbDataAdapter1.SelectCommand = this.oleDbSelectCommand1;
			this.oleDbDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
																										new System.Data.Common.DataTableMapping("Table", "Customers", new System.Data.Common.DataColumnMapping[] {
																																																					 new System.Data.Common.DataColumnMapping("CustID", "CustID"),
																																																					 new System.Data.Common.DataColumnMapping("CustName", "CustName")})});
			this.oleDbDataAdapter1.UpdateCommand = this.oleDbUpdateCommand1;
			//
			// oleDbDeleteCommand1
			//
			this.oleDbDeleteCommand1.CommandText = "DELETE FROM Customers WHERE (CustID = ?) AND (CustName = ? OR ? IS NULL AND CustN" +
				"ame IS NULL)";
			this.oleDbDeleteCommand1.Connection = this.oleDbCon1;
			this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_CustID", System.Data.OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "CustID", System.Data.DataRowVersion.Original, null));
			this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_CustName", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "CustName", System.Data.DataRowVersion.Original, null));
			this.oleDbDeleteCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_CustName1", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "CustName", System.Data.DataRowVersion.Original, null));
			//
			// oleDbInsertCommand1
			//
			this.oleDbInsertCommand1.CommandText = "INSERT INTO Customers(CustName) VALUES (?)";
			this.oleDbInsertCommand1.Connection = this.oleDbCon1;
			this.oleDbInsertCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("CustName", System.Data.OleDb.OleDbType.VarWChar, 50, "CustName"));
			//
			// oleDbSelectCommand1
			//
			this.oleDbSelectCommand1.CommandText = "SELECT CustID, CustName FROM Customers";
			this.oleDbSelectCommand1.Connection = this.oleDbCon1;
			//
			// oleDbUpdateCommand1
			//
			this.oleDbUpdateCommand1.CommandText = "UPDATE Customers SET CustName = ? WHERE (CustID = ?) AND (CustName = ? OR ? IS NU" +
				"LL AND CustName IS NULL)";
			this.oleDbUpdateCommand1.Connection = this.oleDbCon1;
			this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("CustName", System.Data.OleDb.OleDbType.VarWChar, 50, "CustName"));
			this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_CustID", System.Data.OleDb.OleDbType.Integer, 0, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "CustID", System.Data.DataRowVersion.Original, null));
			this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_CustName", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "CustName", System.Data.DataRowVersion.Original, null));
			this.oleDbUpdateCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("Original_CustName1", System.Data.OleDb.OleDbType.VarWChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "CustName", System.Data.DataRowVersion.Original, null));
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion
	}
}
